package com.tbit.uqbike.webmanager.sms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tbit.uqbike.webmanager.util.HttpClientUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;


/**
 * @Author: chen
 * @Description: 创蓝智云短信实名工具类
 * @Date: 创建于 15:31 2021/6/18
 */
@Slf4j
public class ClzySmsAuthUtil {

    /**
     * 实名认证签名校验地址
     */
    private static String URLV2 = "https://api.253.com/open/idcard/id-card-auth/vs";
    /**
     * 实名认证普通地址
     */
    private static String URL = "https://api.253.com/open/idcard/id-card-auth";

    /**
     * 国内短信发送
     *
     * @param
     * @param account  用户名
     * @param password 密码
     * @param msg      短信内容 模板需要完整内容配置，签名需要申请
     * @param phone    手机号码，多个用英文逗号分割
     * @return
     */
    public static boolean sendSms(String account, String password, String msg, String phone) {
        String url = "http://smssh1.253.com/msg/v1/send/json";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("account", account);
        jsonObject.put("password", password);
        jsonObject.put("msg", msg);
        jsonObject.put("phone", phone);
        String json = jsonObject.toJSONString();
        try {
            String tmp = HttpClientUtils.httpJson(url, json);
            JSONObject jsonObject1 = JSON.parseObject(tmp);
            String errCode = jsonObject1.getString("code");
            if ("0".equals(errCode)) {
                return true;
            } else {
                String errMsg = jsonObject1.getString("errorMsg");
                log.error(errMsg);
            }
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
        return false;
    }

    public static void main(String[] args) {

        String key = "account=YZM7705342&password=0678Mokvcqa193";
        String[] strings = key.split("&");
        String account = strings[0].substring(strings[0].indexOf("=") + 1);
        String password = strings[1].substring(strings[1].indexOf("=") + 1);
        String code = "1647";
        System.out.println(account);
        System.out.println(password);
//        sendSms("YZM7705342","0678Mokvcqa193","【大量出行】您正在申请手机注册,验证码为:123456,5分钟内有效!","15070641821");
        sendSms(account, password, "【大量出行】您正在申请手机注册,验证码为:" + code + ",5分钟内有效!", "15070641821");

    }
}

